package com.heima.controller;


import com.heima.common.Result;
import com.heima.domain.dto.PaetnerDto;
import com.heima.domain.dto.PartnerUpdateDto;
import com.heima.domain.vo.PaetnerByIdVo;
import com.heima.service.PartnerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 合作商表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-06-06
 */
@RestController
@RequestMapping("/api/user-service/partner")
@Api(tags = "合作商管理")
public class PartnerController {

    @Autowired
    private PartnerService partnerService;

    @PostMapping
    @ApiOperation("新增合作商")
    public Boolean addPartner(@RequestBody PaetnerDto dto){
        Boolean flag = partnerService.addPartner(dto);
        return flag;
    }

    @GetMapping("/search")
    @ApiOperation("分页查询合作商")
    public Result getByPage(@RequestParam(required = false) Integer pageIndex,
                            @RequestParam(required = false) Integer pageSize,
                            @RequestParam(required = false) String name){
       Result vo = partnerService.getByPage(pageIndex,pageSize,name);
       return vo;
    }

    @GetMapping("/{id}")
    @ApiOperation("根据Id获取")
    public PaetnerByIdVo getPartnerById(@PathVariable Integer id){
        PaetnerByIdVo vo = partnerService.getPartnerById(id);
        return vo;
    }

    @PutMapping("/{id}")
    @ApiOperation("修改合作商")
    public Boolean updatePartner(@PathVariable Integer id, @RequestBody PartnerUpdateDto dto){
        Boolean flag = partnerService.updatePartner(id,dto);
        return flag;
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除合作商")
    public Boolean daletePartner(@PathVariable Integer id){
        Boolean flag = partnerService.deletePartner(id);
        return flag;
    }

    @GetMapping("/count")
    @ApiOperation("获取合作商数量")
    public Long getPartnerCount(){
        long count = partnerService.count();
        return count;
    }
}
